Atomicity (database systems)

In database systems, atomicity (or atomicness; from Gr. a-tomos, undividable) is one of the ACID transaction properties. In an atomic transaction, a series of database operations either all occur, or nothing occurs. A guarantee of atomicity prevents updates to the database occurring only partially, which can cause greater problems than rejecting the whole series outright. In other words, atomicity means indivisibility and irreducibility.[1]

The etymology of the phrase originates in the Classical Greek concept of a fundamental and indivisible component; see atom.

An example of atomicity is ordering an airline ticket where two actions are required: payment, and a seat reservation. The potential passenger must either:

  1. both pay for and reserve a seat; OR
  2. neither pay for nor reserve a seat.

The booking system does not consider it acceptable for a customer to pay for a ticket without securing the seat, nor to reserve the seat without payment succeeding.

Another example: If one wants to transfer some amount of money from one account to another, he/she would start a procedure to do it, but if a failure occurred, due to atomicty the process, the amount will either be transferred completely or will not even start. Thus atomicity protects the user from losing money due to a failed transaction.

Contents

Orthogonality

Atomicity does not behave completely orthogonally with regard to the other ACID properties of the transactions. For example, isolation relies on atomicity to roll back changes in the event of isolation failures such as deadlock; consistency also relies on rollback in the event of a consistency-violation by an illegal transaction. Finally, atomicity itself relies on durability to ensure the atomicity of transactions even in the face of external failures.

As a result of this, failure to detect errors and manually roll back the enclosing transaction may cause failures of isolation and consistency.

Implementation

Typically, systems implement atomicity by providing some mechanism to indicate which transactions have started and which finished; or by keeping a copy of the data before any changes occurred. Several filesystems have developed methods for avoiding the need to keep multiple copies of data, using journaling (see journaling file system). Databases usually implement this using some form of logging/journaling to track changes. The system synchronizes the logs (often the metadata) as necessary once the actual changes have successfully taken place. Afterwards, crash recovery simply ignores incomplete entries. Although implementations vary depending on factors such as concurrency issues, the principle of atomicity — i.e. complete success or complete failure — remain.

Ultimately, any application-level implementation relies on operating-system functionality, which in turn makes use of specialized hardware to guarantee that an operation remains non-interruptible: either by software attempting to re-divert system resources (see pre-emptive multitasking) or by resource-unavailability (such as power-outages). For example, POSIX-compliant systems provide the open(2) system call that allows applications to atomically open a file. Other popular system-calls that may assist in achieving atomic operations from userspace include fcntl(2), fdatasync(2), flock(2), fsync(2), mkdir(2), rasctl(2) (NetBSD re-startable sequences), rename(2), semop(2), sem_post(2), and sem_wait(2).

The hardware level requires atomic operations such as test-and-set (TAS), or atomic increment/decrement operations. In their absence, or when necessary, raising the interrupt level to disable all possible interrupts (of hardware and software origin) may serve to implement the atomic synchronization function primitives. Systems often implement these low-level operations in machine language or in assembly language.

In NoSQL data stores with eventual consistency, the atomicity is also weaker specified than in relational database systems, and exists only in rows (i.e. column families).[2]

References

  1. ^ "atomic operation". http://www.webopedia.com/: Webopedia. http://www.webopedia.com/TERM/A/atomic_operation.html. Retrieved 2011-03-23. "An operation during which a processor can simultaneously read a location and write it in the same bus operation. This prevents any other processor or I/O device from writing or reading memory until the operation is complete." 
  2. ^ Olivier Mallassi (2010-06-09). "Let’s play with Cassandra… (Part 1/3)". http://blog.octo.com/en/: OCTO Talks!. http://blog.octo.com/en/nosql-lets-play-with-cassandra-part-13/. Retrieved 2011-03-23. "Atomicity is also weaker than what we are used to in the relational world. Cassandra guarantees atomicity within a ColumnFamily so for all the columns of a row." 

See also